import Vue from 'vue'

import Cookies from 'js-cookie'

import 'normalize.css/normalize.css' // a modern alternative to CSS resets

import Element from 'element-ui'
import './styles/element-variables.scss'
// import enLang from 'element-ui/lib/locale/lang/en'// 如果使用中文语言包请默认支持，无需额外引入，请删除该依赖

import 'font-awesome/css/font-awesome.min.css'
// 国际化
import locale from 'element-ui/lib/locale/lang/zh-CN' // lang i18n

import '@/styles/index.scss' // global css

import App from './App'
import store from './store'
import router from './router'

import './icons' // icon
import './permission' // permission control
import './utils/error-log' // error log

import * as filters from './filters' // global filters

/**
 * If you don't want to use mock-server
 * you want to use MockJs for mock api
 * you can execute: mockXHR()
 *
 * Currently MockJs will be used in the production environment,
 * please remove it before going online ! ! !
 */
// if (process.env.NODE_ENV === 'production') {
//   const { mockXHR } = require('../mock')
//   mockXHR()
// }

import 'xe-utils'
import VXETable from 'vxe-table'
import 'vxe-table/lib/index.css'
// 引入 vue-ele-form
import EleForm from 'vue-ele-form'

import EleFormImageUploader from 'vue-ele-form-image-uploader'

import EleFormTreeSelect from 'vue-ele-form-tree-select'

// 注册 tree-select 组件
Vue.component('tree-select', EleFormTreeSelect)

Vue.use(VXETable)

Vue.use(Element, {
  size: Cookies.get('size') || 'medium', // set element-ui default size
  locale: locale // 如果使用中文，无需设置，请删除
})

import animated from 'animate.css'

Vue.use(animated)

// 注册 ele-form
Vue.use(EleForm, {
  'tree-select': {
    clearable: true // 所有的 tree-select 都会有 clearable = true的属性值
  }
})

// 注册 image-uploader 组件
Vue.component('image-uploader', EleFormImageUploader)

// register global utility filters
Object.keys(filters).forEach(key => {
  Vue.filter(key, filters[key])
})

Vue.config.productionTip = false

Vue.directive('has', { inserted: function(el, binding, vnode) {
  // 菜单按钮权限
  const btnPermissions = vnode.context.$route.meta.btnPerms
  console.log(btnPermissions)
  var perm = binding.value
  if (btnPermissions && perm) {
    var exist = btnPermissions.some(el => el === perm)
    if (!exist) {
      el.parentNode.removeChild(el)
    }
  }
} })

new Vue({
  el: '#app',
  router,
  store,
  render: h => h(App)
})
